home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Varsity Update 1998 August
/
SGI Varsity Update 1998 August.iso
/
dist
/
dist6.5
/
il_dev.idb
/
usr
/
include
/
il
/
ilError.h.z
/
ilError.h
Wrap
C/C++ Source or Header
|
1998-07-29
|
10KB
|
306 lines
#if 0
Copyright (c) 1991 SGI All Rights Reserved
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
The copyright notice above does not evidence any
actual or intended publication of such source code,
and is an unpublished work by Silicon Graphics, Inc.
This material contains CONFIDENTIAL INFORMATION that
is the property of Silicon Graphics, Inc. Any use,
duplication or disclosure not specifically authorized
by Silicon Graphics is strictly prohibited.
RESTRICTED RIGHTS LEGEND:
Use, duplication or disclosure by the Government is
subject to restrictions as set forth in subdivision
(c)(1)(ii) of the Rights in Technical Data and Computer
Software clause at DFARS 52.227-7013, and/or in similar
or successor clauses in the FAR, DOD or NASA FAR
Supplement. Unpublished- rights reserved under the
Copyright Laws of the United States. Contractor is
SILICON GRAPHICS, INC., 2011 N. Shoreline Blvd.,
Mountain View, CA 94039-7311
#endif
/*
* ilError.h
*
* Error codes, error handling and assertion macros
* used by the IL library.
*/
#ifndef __ilError_h__
#define __ilError_h__
#include <ifl/iflError.h>
#include <pfmt.h> /* for definitions of MM_HALT, etc. */
#ifdef __cplusplus
extern "C" {
#endif
typedef void (ilErrorHandlerFunc)(void *arg, /* closure arg */
int flags, /* includes severity, see pfmt(3)*/
const char *msg, va_list args);
typedef ilErrorHandlerFunc *ilErrorHandlerType;
extern ilErrorHandlerFunc ilNaiveErrorHandler; /* this is the default */
extern ilErrorHandlerFunc ilRobustErrorHandler;
extern ilErrorHandlerFunc ilSilentErrorHandler;
extern void ilGetErrorHandler(ilErrorHandlerType *handler, void **arg);
extern void ilSetErrorHandler(ilErrorHandlerType newhandler, void *newarg);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern void ilError(int flags, const char *msg, ...);
extern void ilErrorV(int flags, const char *msg, va_list);
extern void _ilDebug(const char *msg, ...);
extern void _ilSetThreadErrorHandler(ilErrorHandlerType handler, void *arg);
extern void _ilUnsetThreadErrorHandler();
//
// Convenience class for automatically saving and restoring
// the il Error handler.
// Usage:
// {
// ilSetLocalErrorHandler(my_error_handler, my_arg);
// ... calls to IL that should use my_error_handler ...
// } // original error handler is restored when object goes out of scope
class ilSetLocalErrorHandler {
public:
ilSetLocalErrorHandler(ilErrorHandlerType handler, void *arg)
{
ilGetErrorHandler(&old_handler, &old_arg);
ilSetErrorHandler(handler, arg);
}
/* non-virtual, since always on stack */
~ilSetLocalErrorHandler()
{
ilSetErrorHandler(old_handler, old_arg);
}
protected:
ilErrorHandlerType old_handler;
void *old_arg;
};
//
// Convenience class for temporarily configuring IFL
// to call IL's error handling routine on error.
// Declare one of these objects in the scope where
// this behavior is desired. Example:
//
// {
// iflSetLocalErrorHandlerIL();
// ... calls to IFL functions which should call ilError on error ...
// } // original IFL handling restored when object goes out of scope
//
class iflSetLocalErrorHandlerIL : public iflSetLocalErrorHandler {
public:
iflSetLocalErrorHandlerIL()
: iflSetLocalErrorHandler(call_ilError, NULL) {}
private:
static void call_ilError(void *, int flags, const char *fmt, va_list args)
{
ilErrorV(flags, fmt, args);
}
};
#endif /* __cplusplus */
/*
* Assertion macros:
* ilAssert() -- logically impossible conditions, elided from shipped code
* ilAlwaysAssert() -- logically impossible conditions,
* kept (but less verbose) in shipped code
*/
extern void __ilAssert(const char *, const char *, int);
#ifdef NDEBUG
#define ilAssert(EX) ((void)0)
#define ilAlwaysAssert(EX) ((EX)?((void)0):__ilAssert(0,__FILE__,__LINE__))
#define ilDebug(args) ((void)0)
#else /* !NDEBUG */
#define ilAssert(EX) ((EX)?((void)0):__ilAssert( # EX ,__FILE__,__LINE__))
#define ilAlwaysAssert(EX) ((EX)?((void)0):__ilAssert( # EX ,__FILE__,__LINE__))
#define ilDebug(args) _ilDebug args
#endif /* !NDEBUG */
/* ilStatus encodes status return values and object states. There are
* three components of an ilStatus code:
*
* unsigned int mainstatus:12 -- il status code
* unsigned int subDomain:4 -- domain of subStatus
* unsigned int subStatus:16 -- subdomain status code
*
* mainstatus encodes a main status code; subStatus encodes an elaboration of
* the main status code from another domain. For example: status might
* be ilOPENFAILED and subStatus might be ENOFILE to indicate why il
* returned ilOPENFAILED. In order to determine what subStatus means
* one must examine subdomain to see whether subStatus contains UNIX errno's,
* etc.
*
* The completely 0 status code, ilOKAY, is reserved. This makes it
* easier for most cases in which the caller does not care
* about the specific value, but only wants to compare with ilOKAY.
*
* Note: this file is included by C code so general comments must use
* the C commenting convention.
*/
enum ilStatus {
ilOKAY = 0
/* Other values are really composed of fields as described above... */
};
#ifndef __cplusplus
typedef enum ilStatus ilStatus;
#endif
/*
* Possible values for mainstatus field of an ilStatus...
*/
enum ilMainStatus {
ilBADFILEREAD = 1, /* Error reading from file */
ilBADFILEWRITE = 2, /* Error writing to file */
ilBADMALLOC = 3, /* malloc() or new returned NULL */
ilBADIMGFMT = 4, /* Bad image file format */
ilBADDIMS = 5, /* Bad dimensions */
ilBADOBJ = 6, /* Bad object on construction */
ilBADATTR = 7, /* Bad attributes */
ilFMTUNSUP = 8, /* Unsupported file format */
ilBADPIXTYPE = 9, /* Bad pixel type */
ilBADCONFIG = 10, /* Unsupported configuration */
ilNORANDOMSEEK = 11, /* Can't do random seek */
ilBADSEEK = 12, /* Error seeking on file */
ilBADDECODE = 13, /* Failure on decompression */
ilREADONLY = 14, /* Object is not writable */
ilBADFIELDSET = 15, /* Failed to set field in file header */
ilBADCOMPRESSION = 16, /* Invalid image compression */
ilNULLOBJ = 17, /* NULL object passed as parameter */
ilBADINPUT = 18, /* Invalid input passed */
ilBADCOLFMT = 19, /* Bad color format */
ilBADOP = 20, /* Bad operation attempted */
ilBADFILEOPEN = 21, /* Error opening file */
ilBADMAGIC = 22, /* Invalid magic number in file */
ilEMPTYFILE = 23, /* File is empty */
ilDATACLIPPED = 24, /* Data has been clipped */
ilOUTOFBOUND = 25, /* Parameter(s) out of bounds */
ilTOOMANYLOCKED = 26, /* Too many pages locked in image cache */
ilLUTSIZEMISMATCH = 27, /* No. of channels in lut&image incompatible */
ilZERODIVIDE = 28, /* Attempted to divide by zero */
ilUNSUPPORTED = 29, /* Attempted operation is unsupported */
ilBADPAGEDIMS = 30, /* TIFF page dims must be multiples of 8*/
ilBADTIFFDIR = 31, /* Could not index into TIFF directory */
ilNOTRESIDENT = 32, /* Page is not resident in cache */
ilHWACCELFAIL = 33, /* Unable to complete hw accel operation */
ilHWACCELNEVER = 34, /* Unable to complete hw accel operation */
ilPARKED = 35, /* Request has been parked (don't ask) */
ilUNIMPLEMENTED = 36, /* Unimplemented */
ilIFL_ERROR = 37, /* IFL error */
ilFAILED = 38, /* Operation failed */
ilNOTLOCKED = 39, /* Unlocked ilLockRequest */
ilBADINPUTSTATUS = 40, /* Input image has bad status */
ilABORTED = 41, /* Operation was aborted */
ilAPPROXIMATE = 42 /* Result is not exact */
/* if values are added here, they must be added to ilMainStatusToString */
};
#ifndef __cplusplus
typedef enum ilMainStatus ilMainStatus;
#endif
/*
* Possible values for subDomain field of an ilStatus...
*/
enum ilSubDomain {
ilSubDomainNONE = iflSubDomainNONE,
/* no subdomain; subStatus not meaningful */
ilSubDomainUNIX = iflSubDomainUNIX,
/* subStatus encodes UNIX errno */
ilSubDomainIFL = iflLastSubDomain+1,
ilLastSubDomain = ilSubDomainIFL
};
#ifndef __cplusplus
typedef enum ilSubDomain ilSubDomain;
#endif
/* iflStatus encoding functions (only C++ is supported).
*/
#ifdef __cplusplus
inline ilStatus
ilStatusEncode(unsigned int mainstatus,
unsigned int subDomain = ilSubDomainNONE,
unsigned int subStatus = 0)
{
return (ilStatus) (((mainstatus&0x0fff) << 0)
| ((subDomain &0x000f) << 12)
| ((subStatus &0xffff) << 16));
}
#endif
/* ilStatus decoding functions
*/
#define ilGetMainStatus(ilstatus) ((ilMainStatus)(((ilstatus)>>0) & 0x0fff))
#define ilGetSubDomain(ilstatus) ((ilSubDomain)(((ilstatus)>>12) & 0x000f))
#define ilGetSubStatus(ilstatus) ((unsigned int)(((ilstatus)>>16) & 0xffff))
#ifdef __cplusplus
extern "C" {
#endif
/*
* Composes an error message into a caller-supplied buffer.
* Puts at most returnbufsize-1 bytes in the buffer, and null-terminates
* (unless returnbufsize <= 0).
*/
extern char *ilStatusToString(ilStatus status, char buf[], int bufsize);
extern const char *ilMainStatusToString(ilMainStatus status);
#ifdef __cplusplus
}
#endif
/*
* Convert an iflStatus into an ilStatus (only C++ is supported).
*
* If the iflStatus has a subdomain,
* then change the main code to ilIFL_ERROR (the old main code is lost)
* and retain the old subdomain and subcode.
* XXX (If we had a mapping from IFL main codes to IL main codes,
* we could use that instead of ilIFL_ERROR, but we don't currently).
*
* Otherwise (if the subdomain is NONE),
* set the new main code to ilIFL_ERROR,
* set the new subdomain to IFL,
* and set the new subcode to be the old main code.
*/
#ifdef __cplusplus
inline ilStatus ilStatusFromIflStatus(iflStatus iflstatus)
{
if (iflstatus == iflOKAY)
return ilOKAY;
if (iflGetSubDomain(iflstatus) != iflSubDomainNONE)
return ilStatusEncode(ilIFL_ERROR,
iflGetSubDomain(iflstatus),
iflGetSubStatus(iflstatus));
else
return ilStatusEncode(ilIFL_ERROR,
ilSubDomainIFL,
iflGetMainStatus(iflstatus));
}
#endif
#endif /* __ilError_h__ */